package GUI.Demo01;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class D02 {
    public static void main(String[] args) {
        Frame frame = new Frame();
        Panel panel = new Panel();
        //设置布局,若不设置面板就会占据全部空间
        frame.setLayout(null);
        frame.setBounds(300,300,500,500);
        frame.setBackground(new Color(0x0000FF));
        //panel设置坐标（相对于frame）
        panel.setBounds(50,50,400,400);
        panel.setBackground(new Color(0x00FFFF));
        frame.add(panel);
        frame.setVisible(true);
        //监听窗口关闭事件
        //适配器模式:
        frame.addWindowListener(new WindowAdapter() {
            //指窗口点击关闭时要做的事情
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}
